package com.chengzhi.eshopinventory.request;

import com.chengzhi.eshopinventory.entity.Inventory;
import com.chengzhi.eshopinventory.service.InventoryService;

/**
 * @description 库存更新操作
 * @author: ruanchengzhi
 * @create: 2021-04-01 16:46
 **/
public class InventoryUpdateRequest implements BaseRequest {

    private InventoryService inventoryService;

    private Inventory inventory;

    public InventoryUpdateRequest(InventoryService inventoryService, Inventory inventory) {
        this.inventoryService = inventoryService;
        this.inventory = inventory;
    }

    /**
     * 删除缓存更新数据库
     *
     * @param
     * @return void
     * @author ruanchengzhi
     * @date 2021/4/1
     */
    @Override
    public void execute() {
        this.inventoryService.removeRedisInventory(inventory);
        this.inventoryService.updateInventory(inventory);
    }

    @Override
    public Long getInventoryId() {
        return inventory.getId();
    }

    @Override
    public boolean isForcedRefresh() {
        return Boolean.FALSE;
    }
}
